package com.cloudlead.common.persistence;

import com.mysema.query.sql.Configuration;
import com.mysema.query.sql.MySQLTemplates;
import com.mysema.query.sql.SQLQueryFactory;
import com.mysema.query.sql.types.DateTimeType;
import com.mysema.query.sql.types.LocalDateType;

import javax.sql.DataSource;

/**
 * 领域查询对象创建工厂
 *
 * @author dean.lu
 */
public final class QueryDslConfig {

    private final DataSource dataSource;
    private final Configuration configuration;

    private final SQLQueryFactory sqlQueryFactory;

    public QueryDslConfig(DataSource dataSource) {
        this(dataSource, new Configuration(new MySQLTemplates()));

    }

    public QueryDslConfig(DataSource dataSource, Configuration configuration) {
        super();
        this.dataSource = dataSource;
        this.configuration = configuration;
        configuration.register(new DateTimeType());
        configuration.register(new LocalDateType());
        sqlQueryFactory = new SQLQueryFactory(configuration, dataSource);
    }


    public SQLQueryFactory getSqlQueryFactory() {
        return sqlQueryFactory;
    }

    public DataSource getDataSource() {
        return dataSource;
    }

    public Configuration getConfiguration() {
        return configuration;
    }
}
